package tool;


import javax.swing.*;
import java.awt.*;

public class DrawLinesAndPointsWithAnnotations extends JPanel {
    private final int[][] lineCoordinates; // 线的坐标数组，每个元素包含起始点和结束点的坐标
    private final int[][] pointCoordinates; // 点的坐标数组
    private final String[] lineAnnotations; // 线的注释文本数组
    private final String[] pointAnnotations; // 点的注释文本数组

    public DrawLinesAndPointsWithAnnotations(int[][] lineCoordinates, String[] lineAnnotations, int[][] pointCoordinates, String[] pointAnnotations) {
        this.lineCoordinates = lineCoordinates;
        this.lineAnnotations = lineAnnotations;
        this.pointCoordinates = pointCoordinates;
        this.pointAnnotations = pointAnnotations;
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);

        // 绘制线并添加注释
        for (int i = 0; i < lineCoordinates.length; i++) {
            int x1 = lineCoordinates[i][0];
            int y1 = lineCoordinates[i][1];
            int x2 = lineCoordinates[i][2];
            int y2 = lineCoordinates[i][3];
            g.drawLine(x1, y1, x2, y2);

            // 在线的中点绘制注释文本
            int midX = (x1 + x2) / 2;
            int midY = (y1 + y2) / 2;
            g.drawString(lineAnnotations[i], midX, midY);
        }

        // 绘制点并添加注释
        for (int i = 0; i < pointCoordinates.length; i++) {
            int x = pointCoordinates[i][0];
            int y = pointCoordinates[i][1];
            g.fillOval(x - 3, y - 3, 6, 6); // 绘制点，假设点的直径为6像素

            // 在点的右上方绘制注释文本
            g.drawString(pointAnnotations[i], x + 5, y - 5);
        }
    }
}

